﻿using System;
using System.Collections.Generic;
using SharpSqlAnalyzer.nodes;
using SharpSqlAnalyzer.nodes.hive;
using SharpSqlAnalyzer.nodes.oracle;
using SharpSqlAnalyzer.stmt.mssql;

namespace SharpSqlAnalyzer.stmt
{
	// Token: 0x020000B2 RID: 178
	public class TInsertSqlStatement : TCustomSqlStatement
	{
		// Token: 0x170000E5 RID: 229
		// (get) Token: 0x060005AA RID: 1450 RVA: 0x002FD537 File Offset: 0x002FB737
		// (set) Token: 0x060005AB RID: 1451 RVA: 0x002FD53F File Offset: 0x002FB73F
		public virtual TErrorLoggingClause ErrorLoggingClause
		{
			get
			{
				return this._errorLoggingClause;
			}
			set
			{
				this._errorLoggingClause = value;
			}
		}

		// Token: 0x170000E6 RID: 230
		// (get) Token: 0x060005AC RID: 1452 RVA: 0x002FD548 File Offset: 0x002FB748
		// (set) Token: 0x060005AD RID: 1453 RVA: 0x002FD550 File Offset: 0x002FB750
		public virtual EHiveInsertType HiveInsertType
		{
			get
			{
				return this._hiveInsertType;
			}
			set
			{
				this._hiveInsertType = value;
			}
		}

		// Token: 0x170000E7 RID: 231
		// (get) Token: 0x060005AE RID: 1454 RVA: 0x002FD559 File Offset: 0x002FB759
		// (set) Token: 0x060005AF RID: 1455 RVA: 0x002FD561 File Offset: 0x002FB761
		public virtual TObjectName DirectoryName
		{
			get
			{
				return this._directoryName;
			}
			set
			{
				this._directoryName = value;
			}
		}

		// Token: 0x170000E8 RID: 232
		// (get) Token: 0x060005B0 RID: 1456 RVA: 0x002FD56A File Offset: 0x002FB76A
		// (set) Token: 0x060005B1 RID: 1457 RVA: 0x002FD572 File Offset: 0x002FB772
		public virtual List<TInsertCondition> InsertConditions
		{
			get
			{
				return this._insertConditions;
			}
			set
			{
				this._insertConditions = value;
			}
		}

		// Token: 0x170000E9 RID: 233
		// (get) Token: 0x060005B2 RID: 1458 RVA: 0x002FD57B File Offset: 0x002FB77B
		// (set) Token: 0x060005B3 RID: 1459 RVA: 0x002FD583 File Offset: 0x002FB783
		public virtual List<TInsertIntoValue> InsertIntoValues
		{
			get
			{
				return this._insertIntoValues;
			}
			set
			{
				this._insertIntoValues = value;
			}
		}

		// Token: 0x170000EA RID: 234
		// (get) Token: 0x060005B5 RID: 1461 RVA: 0x002FD595 File Offset: 0x002FB795
		// (set) Token: 0x060005B4 RID: 1460 RVA: 0x002FD58C File Offset: 0x002FB78C
		public virtual TSourceToken InsertToken
		{
			get
			{
				return this._insertToken;
			}
			set
			{
				this._insertToken = value;
			}
		}

		// Token: 0x170000EB RID: 235
		// (get) Token: 0x060005B6 RID: 1462 RVA: 0x002FD59D File Offset: 0x002FB79D
		// (set) Token: 0x060005B7 RID: 1463 RVA: 0x002FD5A5 File Offset: 0x002FB7A5
		public virtual TSelectSqlStatement SubQuery
		{
			get
			{
				return this._subQuery;
			}
			set
			{
				this._insertSource = EInsertSource.subquery;
				this._subQuery = value;
			}
		}

		// Token: 0x170000EC RID: 236
		// (get) Token: 0x060005B8 RID: 1464 RVA: 0x002FD5B5 File Offset: 0x002FB7B5
		// (set) Token: 0x060005B9 RID: 1465 RVA: 0x002FD5BD File Offset: 0x002FB7BD
		public virtual TFunctionCall FunctionCall
		{
			get
			{
				return this._functionCall;
			}
			set
			{
				this._functionCall = value;
			}
		}

		// Token: 0x170000ED RID: 237
		// (get) Token: 0x060005BA RID: 1466 RVA: 0x002FD5C6 File Offset: 0x002FB7C6
		// (set) Token: 0x060005BB RID: 1467 RVA: 0x002FD5CE File Offset: 0x002FB7CE
		public virtual TObjectName RecordName
		{
			get
			{
				return this._recordName;
			}
			set
			{
				this._recordName = value;
			}
		}

		// Token: 0x170000EE RID: 238
		// (get) Token: 0x060005BC RID: 1468 RVA: 0x002FD5D7 File Offset: 0x002FB7D7
		// (set) Token: 0x060005BD RID: 1469 RVA: 0x002FD5DF File Offset: 0x002FB7DF
		public virtual EInsertSource InsertSource
		{
			get
			{
				return this._insertSource;
			}
			set
			{
				this._insertSource = value;
			}
		}

		// Token: 0x170000EF RID: 239
		// (get) Token: 0x060005BE RID: 1470 RVA: 0x002FD5E8 File Offset: 0x002FB7E8
		// (set) Token: 0x060005BF RID: 1471 RVA: 0x002FD5F0 File Offset: 0x002FB7F0
		[Obsolete("use InsertSource instead")]
		public virtual int ValueType
		{
			get
			{
				return this.valueType;
			}
			set
			{
				this.valueType = value;
			}
		}

		// Token: 0x170000F0 RID: 240
		// (get) Token: 0x060005C0 RID: 1472 RVA: 0x002FD5F9 File Offset: 0x002FB7F9
		// (set) Token: 0x060005C1 RID: 1473 RVA: 0x002FD601 File Offset: 0x002FB801
		public virtual TMultiTargetList Values
		{
			get
			{
				return this._values;
			}
			set
			{
				this._values = value;
			}
		}

		// Token: 0x170000F1 RID: 241
		// (get) Token: 0x060005C2 RID: 1474 RVA: 0x002FD60A File Offset: 0x002FB80A
		// (set) Token: 0x060005C3 RID: 1475 RVA: 0x002FD612 File Offset: 0x002FB812
		public virtual TResultColumnList OnDuplicateKeyUpdate
		{
			get
			{
				return this._onDuplicateKeyUpdate;
			}
			set
			{
				this._onDuplicateKeyUpdate = value;
			}
		}

		// Token: 0x170000F2 RID: 242
		// (get) Token: 0x060005C4 RID: 1476 RVA: 0x002FD61B File Offset: 0x002FB81B
		// (set) Token: 0x060005C5 RID: 1477 RVA: 0x002FD623 File Offset: 0x002FB823
		public virtual TSourceToken Ignore
		{
			get
			{
				return this._ignore;
			}
			set
			{
				this._ignore = value;
			}
		}

		// Token: 0x170000F3 RID: 243
		// (get) Token: 0x060005C6 RID: 1478 RVA: 0x002FD62C File Offset: 0x002FB82C
		// (set) Token: 0x060005C7 RID: 1479 RVA: 0x002FD634 File Offset: 0x002FB834
		public virtual TSourceToken Priority_delayed
		{
			get
			{
				return this._priority_delayed;
			}
			set
			{
				this._priority_delayed = value;
			}
		}

		// Token: 0x170000F4 RID: 244
		// (get) Token: 0x060005C8 RID: 1480 RVA: 0x002FD63D File Offset: 0x002FB83D
		// (set) Token: 0x060005C9 RID: 1481 RVA: 0x002FD645 File Offset: 0x002FB845
		public virtual TResultColumnList SetColumnValues
		{
			get
			{
				return this._setColumnValues;
			}
			set
			{
				this._setColumnValues = value;
			}
		}

		// Token: 0x060005CA RID: 1482 RVA: 0x002FD64E File Offset: 0x002FB84E
		public TInsertSqlStatement(EDbVendor dbvendor) : base(dbvendor)
		{
			this.sqlstatementtype = ESqlStatementType.sstinsert;
		}

		// Token: 0x060005CB RID: 1483 RVA: 0x002FD66C File Offset: 0x002FB86C
		internal override void buildsql()
		{
		}

		// Token: 0x060005CC RID: 1484 RVA: 0x002FD66E File Offset: 0x002FB86E
		internal override void clear()
		{
		}

		// Token: 0x060005CD RID: 1485 RVA: 0x002FD670 File Offset: 0x002FB870
		internal override string getasprettytext()
		{
			return "";
		}

		// Token: 0x060005CE RID: 1486 RVA: 0x002FD677 File Offset: 0x002FB877
		internal virtual void iterate(TVisitorAbs pvisitor)
		{
		}

		// Token: 0x170000F5 RID: 245
		// (get) Token: 0x060005CF RID: 1487 RVA: 0x002FD679 File Offset: 0x002FB879
		// (set) Token: 0x060005D0 RID: 1488 RVA: 0x002FD681 File Offset: 0x002FB881
		public virtual TObjectNameList ColumnList
		{
			get
			{
				return this._columnList;
			}
			set
			{
				this._columnList = value;
			}
		}

		// Token: 0x170000F6 RID: 246
		// (get) Token: 0x060005D1 RID: 1489 RVA: 0x002FD68A File Offset: 0x002FB88A
		// (set) Token: 0x060005D2 RID: 1490 RVA: 0x002FD692 File Offset: 0x002FB892
		public virtual TMssqlExecute ExecuteStmt
		{
			get
			{
				return this._executeStmt;
			}
			set
			{
				this._executeStmt = value;
			}
		}

		// Token: 0x060005D3 RID: 1491 RVA: 0x002FD69C File Offset: 0x002FB89C
		public override int doParseStatement(TCustomSqlStatement psql)
		{
			if (this.rootNode == null)
			{
				return -1;
			}
			TInsertSqlNode tinsertSqlNode = (TInsertSqlNode)this.rootNode;
			if (this.sourcetokenlist.size() == 0)
			{
				base.startToken = tinsertSqlNode.startToken;
				base.endToken = tinsertSqlNode.endToken;
			}
			base.doParseStatement(psql);
			this.valueType = tinsertSqlNode.ValueType;
			if (this.dbvendor == EDbVendor.dbvhive)
			{
				this._hiveInsertType = tinsertSqlNode.HiveInsertType;
				this._directoryName = tinsertSqlNode.DirectoryName;
			}
			if (tinsertSqlNode.InsertConditions != null)
			{
				this.valueType = 9;
				this._insertConditions = tinsertSqlNode.InsertConditions;
				foreach (TInsertCondition tinsertCondition in this._insertConditions)
				{
					tinsertCondition.doParse(this, ESqlClause.insertValues);
				}
				this.TargetTable = this._insertConditions[0].InsertIntoValues[0].Table;
			}
			if (tinsertSqlNode.InsertIntoValues != null)
			{
				this.valueType = 9;
				this._insertIntoValues = tinsertSqlNode.InsertIntoValues;
				foreach (TInsertIntoValue tinsertIntoValue in this.InsertIntoValues)
				{
					tinsertIntoValue.doParse(this, ESqlClause.insertValues);
				}
				this.TargetTable = this._insertIntoValues[0].Table;
			}
			this._insertToken = tinsertSqlNode.InsertToken;
			base.scanOracleHint(this._insertToken);
			this._ignore = tinsertSqlNode.Ignore;
			this._priority_delayed = tinsertSqlNode.Priority_delayed;
			if (tinsertSqlNode.cteList != null)
			{
				this.CteList = tinsertSqlNode.cteList;
				this.CteList.doParse(this, ESqlClause.cte);
			}
			if (tinsertSqlNode.TopClause != null)
			{
				tinsertSqlNode.TopClause.doParse(this, ESqlClause.top);
				this.TopClause = tinsertSqlNode.TopClause;
			}
			if (this.valueType != 9 && tinsertSqlNode.TargetTable != null)
			{
				TTable ttable = this.analyzeFromTable(tinsertSqlNode.TargetTable, new bool?(true));
				ttable.EffectType = ETableEffectType.tetInsert;
				this.TargetTable = ttable;
			}
			if (tinsertSqlNode.ColumnList != null)
			{
				this._columnList = tinsertSqlNode.ColumnList;
				for (int i = 0; i < tinsertSqlNode.ColumnList.size(); i++)
				{
					TObjectName objectName = tinsertSqlNode.ColumnList.getObjectName(i);
					objectName.Location = ESqlClause.insertColumn;
					this.TargetTable.ObjectNameReferences.addObjectName(objectName);
					this.TargetTable.LinkedColumns.addObjectName(objectName);
					objectName.SourceTable = this.TargetTable;
				}
			}
			if (tinsertSqlNode.OutputClause != null)
			{
				tinsertSqlNode.OutputClause.doParse(this, ESqlClause.output);
				this.OutputClause = tinsertSqlNode.OutputClause;
			}
			switch (this.valueType)
			{
			case 1:
				this._insertSource = EInsertSource.values;
				tinsertSqlNode.getValues().doParse(this, ESqlClause.insertValues);
				this._values = tinsertSqlNode.getValues();
				if (this._columnList != null)
				{
					for (int j = 0; j < this._values.size(); j++)
					{
						TMultiTarget multiTarget = this._values.getMultiTarget(j);
						if (multiTarget.ColumnList != null && multiTarget.ColumnList.size() != 0 && multiTarget.ColumnList.getResultColumn(0).Expr != null && multiTarget.ColumnList.getResultColumn(0).Expr.ExpressionType != EExpressionType.subquery_t && multiTarget.ColumnList.size() != this._columnList.size())
						{
							TSourceToken startToken = multiTarget.ColumnList.startToken;
							TSyntaxError se = new TSyntaxError(startToken.ToString(), startToken.lineNo, startToken.columnNo, string.Format("value count({0:D}) is not the same as column list({1:D})", multiTarget.ColumnList.size(), this._columnList.size()), EErrorType.sperror, 10111);
							this.parseerrormessagehandle(se);
						}
					}
				}
				break;
			case 2:
				this._insertSource = EInsertSource.subquery;
				if (this._subQuery == null)
				{
					this._subQuery = new TSelectSqlStatement(this.dbvendor);
					this._subQuery.rootNode = tinsertSqlNode.SubQueryNode;
				}
				this._subQuery.doParseStatement(this);
				break;
			case 3:
				this._insertSource = EInsertSource.default_values;
				break;
			case 4:
				this._insertSource = EInsertSource.execute;
				this._executeStmt = new TMssqlExecute(EDbVendor.dbvmssql);
				this._executeStmt.rootNode = tinsertSqlNode.ExecuteSqlNode;
				this._executeStmt.doParseStatement(this);
				break;
			case 5:
				this._insertSource = EInsertSource.values_function;
				tinsertSqlNode.FunctionCall.doParse(this, ESqlClause.insertValues);
				this._functionCall = tinsertSqlNode.FunctionCall;
				break;
			case 6:
				this._insertSource = EInsertSource.values_empty;
				break;
			case 7:
				this._insertSource = EInsertSource.set_column_value;
				this._setColumnValues = tinsertSqlNode.SetColumnValues;
				this._setColumnValues.doParse(this, ESqlClause.insertValues);
				break;
			case 8:
				this._insertSource = EInsertSource.values_oracle_record;
				tinsertSqlNode.RecordName.doParse(this, ESqlClause.insertValues);
				this._recordName = tinsertSqlNode.RecordName;
				break;
			case 9:
				this._insertSource = EInsertSource.values_multi_table;
				if (this._subQuery == null)
				{
					this._subQuery = new TSelectSqlStatement(this.dbvendor);
					this._subQuery.rootNode = tinsertSqlNode.SubQueryNode;
				}
				this._subQuery.doParseStatement(this);
				break;
			case 11:
				this._insertSource = EInsertSource.hive_query;
				if (this._subQuery == null)
				{
					this._subQuery = new TSelectSqlStatement(this.dbvendor);
					this._subQuery.rootNode = tinsertSqlNode.SubQueryNode;
				}
				this._subQuery.doParseStatement(this);
				break;
			}
			if (tinsertSqlNode.ReturningClause != null)
			{
				tinsertSqlNode.ReturningClause.doParse(this, ESqlClause.returning);
				this.ReturningClause = tinsertSqlNode.ReturningClause;
			}
			if (tinsertSqlNode.OnDuplicateKeyUpdate != null)
			{
				this._onDuplicateKeyUpdate = tinsertSqlNode.OnDuplicateKeyUpdate;
				this._onDuplicateKeyUpdate.doParse(this, ESqlClause.unknown);
			}
			this._errorLoggingClause = tinsertSqlNode.ErrorLoggingClause;
			return 0;
		}

		// Token: 0x060005D4 RID: 1492 RVA: 0x002FDC90 File Offset: 0x002FBE90
		public override void accept(TParseTreeVisitor v)
		{
			v.preVisit(this);
			v.postVisit(this);
		}

		// Token: 0x060005D5 RID: 1493 RVA: 0x002FDCA0 File Offset: 0x002FBEA0
		public override void acceptChildren(TParseTreeVisitor v)
		{
			v.preVisit(this);
			if (this.CteList != null)
			{
				this.CteList.acceptChildren(v);
			}
			if (this.TopClause != null)
			{
				this.TopClause.acceptChildren(v);
			}
			if (this.TargetTable != null)
			{
				this.TargetTable.acceptChildren(v);
			}
			if (this.ColumnList != null)
			{
				this.ColumnList.acceptChildren(v);
			}
			if (this.OutputClause != null)
			{
				this.OutputClause.acceptChildren(v);
			}
			switch (this.ValueType)
			{
			case 1:
				this.Values.acceptChildren(v);
				break;
			case 2:
				this.SubQuery.acceptChildren(v);
				break;
			case 5:
				this.FunctionCall.acceptChildren(v);
				break;
			case 7:
				this.SetColumnValues.acceptChildren(v);
				break;
			case 8:
				this.RecordName.acceptChildren(v);
				break;
			}
			if (this.ReturningClause != null)
			{
				this.ReturningClause.acceptChildren(v);
			}
			v.postVisit(this);
		}

		// Token: 0x04001153 RID: 4435
		private TErrorLoggingClause _errorLoggingClause;

		// Token: 0x04001154 RID: 4436
		private EHiveInsertType _hiveInsertType = EHiveInsertType.intoUnknown;

		// Token: 0x04001155 RID: 4437
		private TObjectName _directoryName;

		// Token: 0x04001156 RID: 4438
		private List<TInsertCondition> _insertConditions;

		// Token: 0x04001157 RID: 4439
		private List<TInsertIntoValue> _insertIntoValues;

		// Token: 0x04001158 RID: 4440
		private TSourceToken _insertToken;

		// Token: 0x04001159 RID: 4441
		private TSelectSqlStatement _subQuery;

		// Token: 0x0400115A RID: 4442
		private TFunctionCall _functionCall;

		// Token: 0x0400115B RID: 4443
		private TMssqlExecute _executeStmt;

		// Token: 0x0400115C RID: 4444
		private TObjectName _recordName;

		// Token: 0x0400115D RID: 4445
		private EInsertSource _insertSource;

		// Token: 0x0400115E RID: 4446
		private TMultiTargetList _values;

		// Token: 0x0400115F RID: 4447
		private int valueType = 1;

		// Token: 0x04001160 RID: 4448
		private TResultColumnList _setColumnValues;

		// Token: 0x04001161 RID: 4449
		private TSourceToken _ignore;

		// Token: 0x04001162 RID: 4450
		private TSourceToken _priority_delayed;

		// Token: 0x04001163 RID: 4451
		private TResultColumnList _onDuplicateKeyUpdate;

		// Token: 0x04001164 RID: 4452
		private TObjectNameList _columnList;
	}
}
